package com.leetcode.algorithm.y22.m07.w5;

import java.util.ArrayDeque;
import java.util.Deque;

import com.leetcode.algorithm.common.ListNode;

/**
 * 234. 回文链表
 * 
 * https://leetcode.cn/problems/palindrome-linked-list/
 * 
 * @author jie.deng
 *
 */
class Question0234Solution01 {
	
	public boolean isPalindrome(ListNode head) {
		Deque<Integer> stack = new ArrayDeque<>();
		ListNode cur = head;
		while (cur != null) {
			stack.push(cur.val);
			cur = cur.next;
		}

		cur = head;
		while (cur != null) {
			if (cur.val != stack.pop().intValue()) {
				return false;
			}
			cur = cur.next;
		}

		return true;
	}
    
}